<?php
class tourism_order_product_profit_model extends CI_Model
{
    private $table = 'tourism_order_product_profit';

    public function insertBatch($postData)
    {
        if (empty($postData)) {
            return false;
        }
        foreach ($postData as $key=>$value) {
            if (empty($value)) {
                return false;
            }
            foreach ($value as $v) {
                $data[] = array(
                    'order_product_id' => $key,
                    'uid'              => $v['uid'],
                    'account'          => $v['account'],
                    'account_type'     => $v['account_type'],
                    'as'               => $v['as'],
                    'bit_trade'        => $v['bit_trade']
                );
            }
        }
        return $this->db->insert_batch($this->table, $data);
    }

    public function addBatch($postData)
    {
        if (empty($postData)) {
            return false;
        }
        return $this->db->insert_batch($this->table, $postData);
    }

    public function delete($order_product_id)
    {
        $this->db->where('order_product_id', $order_product_id);
        return $this->db->delete($this->table);
    }

    public function findById($order_product_id)
    {
        $this->db->where('order_product_id', $order_product_id);
        return $this->db->get($this->table);
    }
}